//
//  HJDConsultController.m
//  JYHospital
//
//  Created by 胡金东 on 16/3/31.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "HJDHomeController.h"
#import "HJDYiYuanViewController.h"


#import "HJDHealthViewController.h"
#import "HJDSetViewController.h"
#import "HJDSetDateViewController.h"
#import "HJDCalculateDateViewController.h"
#import "HJDEVersionViewController.h"

#import "HJDMondayTableViewController.h"
#import "HJDLabel.h"
#import "HJDTuesdayTableViewController.h"
#import "HJDWednesdayTableViewController.h"
#import "HJDThursdayTableViewController.h"
#import "HJDFridayTableViewController.h"
#import "HJDSaturdayTableViewController.h"
#import "HJDSundayTableViewController.h"

#import "HJDBannerOneViewController.h"
#import "HJDBannerTwoViewController.h"
#import "HJDBannerThreeViewController.h"
#import "HJDBannerFourViewController.h"
#import "HJDBannerFiveViewController.h"

#import "HJDCTimeViewController.h"
#import "HJDDetailTimeTableViewController.h"
#import "HJDPapreViewController.h"

//孕期管理
#import "HJDPofileControllerr.h"
//一键挂号
#import "HJDRegistrationViewController.h"
//孕期档案
#import "HJDGestationViewController.h"

#import "HJDLoginViewController.h"

#import "AFNetworking.h"
#import "MJExtension.h"
#import "MBProgressHUD.h"
#import "RESideMenu.h"
#import "HJDTabBarController.h"
//#import "HJDPesonalCenterViewController.h"
#import "HJDNavigationController.h"

#import "BSMacros.h"

#import"MBProgressHUD.h"

#import "HJDFileViewController.h"
#import "HJDNewsTableViewCell.h"
#import "HJDWenZhangViewController.h"
#import "HJDKnowledgeViewController.h"






#define IMAGECOUNT 5
#define margin 5



@interface HJDHomeController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
{
//    m上面天数
    NSInteger n;
//    n是出生天数
    NSInteger m;
    int w;
    NSInteger one;
    BOOL flag;
    int status;
    int S;
   
    NSInteger INDex;
    
    int statusCase;
    
}



//图片轮转
@property (nonatomic,strong)UIScrollView *scrollView;

@property (nonatomic,strong)UIPageControl *pageControl;
@property (nonatomic,strong)NSTimer *timer;
//整体页面
@property (nonatomic,strong)UIScrollView *scroll;
//准备按钮
@property (nonatomic,strong) UIButton *papreBtn;
//第四个按钮
@property (nonatomic,strong) UILabel *fourLbl;

@property (nonatomic,strong)  UIView *viewLbl;


@property (nonatomic,strong) UIScrollView * upScrollView;

@property (nonatomic,strong) UIScrollView * downScrollView;



@property (nonatomic,assign) NSInteger * id;
@property (nonatomic,strong) NSURL * imageurl;

//出生上的天数
@property (nonatomic,strong) UILabel *timeLbl ;

//背景
@property (nonatomic,strong) UIView * backgroundView;

@property (nonatomic,strong) UIView *viewM;

@property (nonatomic,strong) UIImageView *imageView ;
//出生天数
@property (nonatomic,strong) UILabel *babyDayLbl ;
//banner数组
@property (nonatomic,strong)  NSMutableArray * array ;
//月份
@property (nonatomic,strong) UILabel *dateLbl;
//天
@property (nonatomic,strong) UILabel *dayLbl ;

//@property (nonatomic,strong) NSString *flag;


@property (nonatomic,strong) NSString * bannerStr;

@property (nonatomic,strong) UIView *viewTimeSele;

@property (nonatomic,strong) NSMutableArray * idArray;

@property (nonatomic,strong) NSMutableArray * typeArray;


@property (nonatomic,strong) NSString *pregnancy ;

@property (nonatomic,strong) NSMutableDictionary *params ;

//@property (nonatomic,strong) MBProgressHUD * hubb;

@property (nonatomic,strong) UILabel * label ;

@property (nonatomic,strong) UIView *xinQiview;

@property (nonatomic,strong) UITableView * knowledgeTableView;

@property (nonatomic,strong) NSMutableArray * statusArray;


@property (nonatomic,strong) NSMutableArray * wenidArray;

@property (nonatomic,strong) NSMutableArray * wentypeArray;

@property (nonatomic,strong) NSMutableArray * newIdArray;





@end

@implementation HJDHomeController


-(UILabel *)timeLbl
{
    if (_timeLbl ==nil) {
        
        _timeLbl = [[UILabel alloc]init];
    }
    return _timeLbl;
}

-(UILabel *)babyDayLbl
{
    if (_babyDayLbl ==nil) {
        
        _babyDayLbl = [[UILabel alloc]init];
    }
    return _babyDayLbl;
}

-(NSMutableArray *)idArray{
    if (_idArray == nil) {
        _idArray = [NSMutableArray array];
    }
    return _idArray;
}
-(NSMutableArray *)typeArray
{
    if (_typeArray == nil) {
        _typeArray = [NSMutableArray array];
    }
    return _typeArray;
}
-(NSMutableArray *)wenidArray{
    if (_wenidArray == nil) {
        _wenidArray = [NSMutableArray array];
    }
    return _wenidArray;
}
-(NSMutableArray *)wentypeArray
{
    if (_wentypeArray == nil) {
        _wentypeArray = [NSMutableArray array];
    }
    return _wentypeArray;
}

-(NSMutableArray *)newIdArray
{
    if (_newIdArray == nil) {
        _newIdArray = [NSMutableArray array];
    }
    return _newIdArray;
}

-(UILabel *)label
{
    if (_label == nil) {
        _label = [[UILabel alloc]init];
    }
    return _label;
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //隐藏导航栏
    self.navigationController.navigationBarHidden = YES;
    
    NSUserDefaults *defa = [NSUserDefaults standardUserDefaults];
    NSString *phone = [defa objectForKey:@"phonenum"];
    self.pregnancy = [defa objectForKey:@"pregnanc"];
    NSString *url = @"/app/attention.do";
    NSString *path = [Hurl stringByAppendingString:url];
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    self.params = [NSMutableDictionary dictionary];
    self.params[@"pregnancy"] = self.pregnancy;
    self.params[@"phone"] = phone;
    [mgr POST:path parameters:self.params progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        
        NSDictionary *info = (NSDictionary *)responseObject;
        NSString *date = info[@"resultMap"][@"date"];
        
        
        self.attenModel = [HJDAttenModel mj_objectWithKeyValues:date];
        
        self.timeLbl.text = [NSString stringWithFormat:@"%ld",(long)self.attenModel.countdown];
        
        if (280-self.attenModel.countdown<=0) {
            self.babyDayLbl.text = @"0";
//            NSLog(@"%ld",280-self.attenModel.countdown);
        }else{
        self.babyDayLbl.text = [NSString stringWithFormat:@"%ld",(long)280-self.attenModel.countdown];
        }
                NSUserDefaults *defa = [NSUserDefaults standardUserDefaults];
                [defa setObject:self.babyDayLbl.text forKey:@"tian"];

        
        n = self.attenModel.countdown;
        [self setUpDate];
        [self setUpUILabel];
        [self setUpChangeTime];
        
        INDex = one;
        if (one ==0) {
            CGPoint offset1 = self.downScrollView.contentOffset;
            offset1.x = self.downScrollView.frame.size.width;
            [self.downScrollView setContentOffset:offset1 animated:YES];
            
        }
        CGPoint offset1 = self.downScrollView.contentOffset;
        offset1.x = one * self.downScrollView.frame.size.width;
        [self.downScrollView setContentOffset:offset1 animated:YES];
        //        加载完成
        _loadingView.alpha=0;
        [_shapeView stopAnimating];

        [self.label removeFromSuperview];
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        [MBProgressHUD showError:@"服务器升级，请稍后再试"];
      
    }];

    
   
   }


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor getColorWithHexNumber:@"F1F1EE"];
    
    [self setUpNavi];
    [self setupScrollView];
    [self setupPageControl];
    
    [self setUpupScrollView];

    
    [self setUpdownScrollView];
    //添加内容
    [self setUpContent];
    //    添加标题
    [self setUpTitle];
    
    [self setUpknowledge];
    
//    for (NSString *familyName in [UIFont familyNames]) {
//        NSLog(@"familyName：%@", familyName);
//        //    if ([familyName isEqualToString:@"test"]) { // 开始时加一个判断条件，发现这样不行。
//        for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
//            NSLog(@"fontName:%@", fontName);
//            //    }
//        }
//        NSLog(@"=====");
//    }
//
    
    //    默认显示第0个子控制器 从0开始

    if (n<=0) {
        n=0;
    }else{
    n = self.attenModel.countdown;
    }

    }

-(void)setUpChangeTime{
    

    if ([self.attenModel.weekTime isEqualToString: @"星期一"]) {
        one = 0;

    }else if ([self.attenModel.weekTime isEqualToString:@"星期二"]){
        one = 1;
    }else if ([self.attenModel.weekTime isEqualToString:@"星期三"]){
        one = 2;
    }else if ([self.attenModel.weekTime isEqualToString:@"星期四"]){
        
        one = 3;
    }else if ([self.attenModel.weekTime isEqualToString:@"星期五"]){
        
        one = 4;
    }else if ([self.attenModel.weekTime isEqualToString:@"星期六"]){
        
        one = 5;
    }else if ([self.attenModel.weekTime isEqualToString:@"星期日"]){
        one = 6;
    }
    
}



-(void)setUpNavi
{
    
    
    self.scroll = [[UIScrollView alloc]initWithFrame:
                   [UIScreen mainScreen].bounds];
    self.scroll.delegate = self;
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.scroll.showsVerticalScrollIndicator = YES;//垂直移动
    self.scroll.showsHorizontalScrollIndicator = NO;//水平移动
    //上下滑动
//    self.scroll.contentSize = CGSizeMake(HJDWidth,1200 ) ;
    
    
    [self.view addSubview: self.scroll];
    //    背景
    self.backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,HJDWidth, 1092/2)];

    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,HJDWidth, 1092/2)];
    self.imageView.image = [UIImage imageNamed:@"首页背景"];
    [self.backgroundView addSubview:self.imageView];

    [self.scroll addSubview:self.backgroundView];
    
    
    
    self.label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height)];
    self.label.backgroundColor = [UIColor getColorWithHexNumber:@"323232"];
//    self.label.font = [UIFont systemFontOfSize:14];
//    self.label.text = @"点击";
    [self.scroll addSubview:self.label];
    
    //设置动画
    CATransition * transion = [CATransition animation];
    transion.type = @"fade";//设置动画方式
    transion.subtype = @"fromBottom";//设置动画从那个方向开始
    [self.label.layer addAnimation:transion forKey:nil];//给Label.layer 添加动画
    //设置延时效果
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10.0 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
//        [self.label removeFromSuperview];
//    });//这句话的意思是1.5秒后，把label移出视图
    

    

    _loadingView=[[UIView alloc] init];
   
    _loadingView.frame=CGRectMake(self.view.frame.size.width/2-100/2, self.view.frame.size.height/2-120/2, 100, 120);
//    _loadingView.frame = CGRectMake(0, 0, HJDWidth, HJDHeight);
//   _loadingView.backgroundColor = [UIColor getColorWithHexNumber:@"323232"];
   
    _loadingView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:_loadingView];
    
    _shapeView=[[ShapeLoadingView alloc] initWithFrame:CGRectMake(0, 0, 100, 120) title:@"加载中..."];
    _shapeView.backgroundColor=[UIColor clearColor];
    [_loadingView addSubview:_shapeView];
    
    _loadingView.alpha=1;
    
    [_shapeView startAnimating];
    
    
    
    
    

    
    
    
    CGFloat leftX = HJDHorizontalMargin;
    CGFloat leftY = HJDVerticalMargin;
    CGFloat leftW = 34;
    CGFloat leftH = 34;
    UIButton *navleftBtn = [[UIButton alloc]initWithFrame:CGRectMake(leftX, leftY, leftW, leftH)];
    [navleftBtn setBackgroundImage:[UIImage imageNamed:@"矢量智能对象侧"] forState:UIControlStateNormal];
    [navleftBtn addTarget:self action:@selector(MyCenterClick) forControlEvents:UIControlEventTouchUpInside];

    [self.backgroundView addSubview:navleftBtn];
    
    
    
//    CGFloat rightX = HJDWidth -35-HJDHorizontalMargin;
//    CGFloat rightY = leftY;
//    CGFloat rightW = 34;
//    CGFloat rightH = 34;
//    UIButton *navrightBtn = [[UIButton alloc]initWithFrame:CGRectMake(rightX, rightY, rightW, rightH)];
//    [navrightBtn addTarget:self action:@selector(push) forControlEvents:UIControlEventTouchUpInside];
//    [navrightBtn setBackgroundImage:[UIImage imageNamed:@"消息"] forState:UIControlStateNormal];
//    [navrightBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateHighlighted];
//
//    [self.backgroundView addSubview:navrightBtn];
    
    CGFloat X = HJDWidth/2- 120/2;
    CGFloat Y = 20;
    CGFloat W = 120;
    CGFloat H = 34;
    self.viewTimeSele = [[UIView alloc]initWithFrame:CGRectMake(X, Y, W, H)];
    self.viewTimeSele.backgroundColor = [UIColor getColorWithHexNumber:@"323232"];
    self.viewTimeSele.alpha = 0.2;
    [self.viewTimeSele setRadius:18 borderWith:0 borderColor:nil];
    [self.backgroundView addSubview:self.viewTimeSele];
    
     self.timeLbl = [[UILabel alloc]init];
    }

-(void)setUpUILabel{
    
//   self.timeLbl = [[UILabel alloc]init];
    self.timeLbl.text = [NSString stringWithFormat:@"%ld",(long)self.attenModel.countdown];
    self.timeLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
 
    self.timeLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:19];
   

    self.timeLbl.textAlignment = NSTextAlignmentCenter;
    CGFloat timeLblW = 40;
    CGFloat timeLblH = 34;
    CGFloat timeLblX = (HJDWidth - 45)/2 -10;
    CGFloat timeLblY = 20;
    
    self.timeLbl.frame = CGRectMake(timeLblX, timeLblY, timeLblW, timeLblH);
    self.timeLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    [self.backgroundView addSubview:self.timeLbl];
    
    UILabel *upLbll = [[UILabel alloc]init];
    upLbll.text = @"天";
    upLbll.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    upLbll.font = [UIFont fontWithName:@"HelveticaNeue" size:19];
//     upLbll.font = [UIFont fontWithName:@"ygyxsziti" size:19];
    
    CGSize LbllSize = [upLbll.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:upLbll.font,NSFontAttributeName, nil]];
    CGFloat LbllX = CGRectGetMaxX(self.timeLbl.frame);
    CGFloat LbllY = timeLblY + 5;
    upLbll.frame = (CGRect){{LbllX,LbllY},LbllSize};
    
    
    upLbll.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    [self.backgroundView addSubview:upLbll];


    
    CGFloat leftImgW = 9;
    CGFloat leftImgH = 35/2;
    CGFloat leftImgX =( HJDWidth- 120)/2 +4;
    CGFloat leftImgY = 28;
    UIImageView *leftImg = [[UIImageView alloc]initWithFrame:CGRectMake(leftImgX, leftImgY, leftImgW, leftImgH)];
    leftImg.image = [UIImage imageNamed:@"首页上"];
    [self.backgroundView addSubview:leftImg];
    
    CGFloat leftBtnX =( HJDWidth- 190)/2;
    CGFloat leftBtnY = 15;
    CGFloat leftBtnW = 60;
    CGFloat leftBtnH = 45;

    UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(leftBtnX, leftBtnY, leftBtnW, leftBtnH)];
    [leftBtn addTarget:self action:@selector(upDayBtnClick) forControlEvents:UIControlEventTouchUpInside];
//    leftBtn.backgroundColor = [UIColor redColor];
    [self.backgroundView addSubview:leftBtn];
    
    
    
    CGFloat rightImgX = leftImgX + 102;
    CGFloat rightImgY = 28;
    CGFloat rightImgW = 9;
    CGFloat rightImgH = 35/2;
    UIImageView *rightImg = [[UIImageView alloc]initWithFrame:CGRectMake(rightImgX, rightImgY, rightImgW, rightImgH)];
    rightImg.image = [UIImage imageNamed:@"︿@2x_0"];
    [self.backgroundView addSubview:rightImg];
    
    
   
    CGFloat rightBtnX = leftImgX + 90;
    CGFloat rightBtnY = 15;
    CGFloat rightBtnW = 60;
    CGFloat rightBtnH = 45;
    UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(rightBtnX, rightBtnY, rightBtnW, rightBtnH)];
//    [rightBtn setBackgroundImage:[UIImage imageNamed:@"︿@2x_0"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(nextDayBtnClick) forControlEvents:UIControlEventTouchUpInside];
//    rightBtn.backgroundColor = [UIColor redColor];
    [self.backgroundView addSubview:rightBtn];
    
    //   出生天数
    CGFloat viewW = 198 /2 + 10;
    CGFloat viewH = 95/2;
    CGFloat viewX = (HJDWidth - viewW)/2;
    CGFloat viewY = CGRectGetMaxY(self.viewTimeSele.frame) + HJDVerticalMargin;
   self.viewLbl = [[UIView alloc]init];
       self.viewLbl.frame = CGRectMake(viewX, viewY, viewW, viewH);
    [   self.viewLbl setRadius:50/2 -2 borderWith:0 borderColor:[UIColor whiteColor]];
       self.viewLbl.backgroundColor = [UIColor getColorWithHexNumber:@"5CC6AB"];
    [self.backgroundView addSubview: self.viewLbl];
    
    UILabel *babyLbl = [[UILabel alloc]init];
    babyLbl.text = @"距宝宝出生";
    babyLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:15];
    CGSize  babyLblSize = [babyLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:babyLbl.font,NSFontAttributeName ,nil]];
    CGFloat babyLblX = (viewW - babyLblSize.width)/2;
    CGFloat babyLblY = 2;
    babyLbl.frame = (CGRect){{babyLblX,babyLblY},babyLblSize};
    babyLbl.textAlignment = NSTextAlignmentCenter;
    babyLbl.textColor = [UIColor whiteColor];
    [self.viewLbl addSubview:babyLbl];
    
   self.babyDayLbl = [[UILabel alloc]init];
    if (280-self.attenModel.countdown<=0) {
        self.babyDayLbl.text = @"0";
//        NSLog(@"%ld",280-self.attenModel.countdown);
    }else{
    self.babyDayLbl.text = [NSString stringWithFormat:@"%ld",280-self.attenModel.countdown];
    }
    self.babyDayLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:24];
    CGSize  babyDayLblSize = [self.babyDayLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.babyDayLbl.font,NSFontAttributeName ,nil]];
    CGFloat babyDayLblW = 50;
    CGFloat babyDayLblH = babyDayLblSize.height;
    CGFloat babyDayLblX = (viewW - 50)/2;
    CGFloat babyDayLblY = CGRectGetMaxY(babyLbl.frame) -2 ;
    self.babyDayLbl.frame = CGRectMake(babyDayLblX, babyDayLblY, babyDayLblW, babyDayLblH);
    self.babyDayLbl.textAlignment = NSTextAlignmentCenter;
    self.babyDayLbl.textColor = [UIColor whiteColor];
    [self.viewLbl addSubview:self.babyDayLbl];
    
    
    CGFloat TLblX = CGRectGetMaxX(self.babyDayLbl.frame);
    CGFloat TLblY = babyDayLblY ;
    CGFloat TLblW = 20;
    CGFloat TLblH = 15;
    UILabel *TLbl = [[UILabel alloc]initWithFrame:CGRectMake(TLblX, TLblY +9, TLblW, TLblH)];
    TLbl.text = @"天";
    TLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:13];
    
        TLbl.textColor = [UIColor getColorWithHexNumber:@"FE93A2"];
    [self.viewLbl addSubview:TLbl];
    

    
}




//个人中心
-(void)MyCenterClick
{
    [self.sideMenuViewController presentLeftMenuViewController];
}
//星期
-(void)setUpupScrollView
{

    
    self.upScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(45,120 , HJDWidth-45-10, 40)];
    self.upScrollView.backgroundColor = [UIColor clearColor];
    
           self.upScrollView.showsHorizontalScrollIndicator = NO;
        self.upScrollView.showsVerticalScrollIndicator = NO;
    self.upScrollView.delegate = self;
    [self.backgroundView addSubview:self.upScrollView];
    
}

-(void)setUpDate{
    NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
    [inputFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSDate *inputDate = [inputFormatter dateFromString:self.attenModel.time];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *comp = [[NSDateComponents alloc]init];
    NSInteger flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    
    comp = [calendar components:flags fromDate:inputDate];
    NSInteger month = [comp month];
    NSInteger day = [comp day];
    
    
    self.xinQiview = [[UIView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(self.upScrollView.frame)-5,HJDWidth-20 , 30)];
    self.xinQiview.backgroundColor = [UIColor whiteColor];
    [self.backgroundView addSubview:self.xinQiview];
    
    CGFloat imageX = 10;
    CGFloat imageY = -25;
    CGFloat imageW = 39/2;
    CGFloat imageH = 109/2;
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(imageX, imageY, imageW, imageH)];
    imageView.image =[UIImage imageNamed:@"别针"];
    [self.xinQiview addSubview:imageView];
    

    
    self.dayLbl = [[UILabel alloc]init];
    self.dayLbl.text = [NSString stringWithFormat:@"%ld.",(long)day];
    self.dayLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:25];
    CGSize  dayLblSize = [self.dayLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.dayLbl.font,NSFontAttributeName ,nil]];
    CGFloat dayLblX = HJDWidth - 80;
    CGFloat dayLblY = 160;
//    CGFloat dayLblW = 35;
//    self.dayLbl.frame = CGRectMake(dayLblX, dayLblY, dayLblW, dayLblSize.height);
    self.dayLbl.frame = (CGRect){{dayLblX,dayLblY},dayLblSize};
    self.dayLbl.textAlignment = NSTextAlignmentCenter;
    self.dayLbl.textColor = [UIColor getColorWithHexNumber:@"CFCFCF"];
    [self.backgroundView addSubview:self.dayLbl];
    
    
    self.dateLbl = [[UILabel alloc]init];
    self.dateLbl.text = [NSString stringWithFormat:@"%ld",(long)month];
    
    self.dateLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:15];
    CGSize  dateLblSize = [self.dateLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.dateLbl.font,NSFontAttributeName ,nil]];
    CGFloat dateLblX = CGRectGetMaxX(self.dayLbl.frame);
    CGFloat dateLblY = dayLblY + 9;
    self.dateLbl.frame = (CGRect){{dateLblX,dateLblY},dateLblSize};
    self.dateLbl.textAlignment = NSTextAlignmentCenter;
    self.dateLbl.textColor = [UIColor getColorWithHexNumber:@"CFCFCF"];
    [self.backgroundView addSubview:self.dateLbl];
    

}


-(void)setUpdownScrollView
{
    CGFloat viewMH = IS_IPHONE_5?300:IS_IPHONE_6?320:IS_IPHONE_6_PLUS?330:300;
    self.viewM = [[UIView alloc]initWithFrame:CGRectMake(10, 180, HJDWidth - 20, viewMH)];
    self.viewM.backgroundColor = [UIColor whiteColor];
    [self.backgroundView addSubview:self.viewM];

    
    
        self.downScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, -10, HJDWidth-20, 120)];
     self.downScrollView.delegate = self;
    self.downScrollView.pagingEnabled = YES;
   
    //    水平滚动条不显示
    self.downScrollView.showsHorizontalScrollIndicator = NO;
    self.downScrollView.showsVerticalScrollIndicator = YES;

////    不让垂直拖动
//    self.downScrollView.alwaysBounceVertical = YES;

//不让水平拖动
    self.downScrollView.alwaysBounceHorizontal = NO;
//    self.downScrollView.bounces = NO;//NO时滚动不会超出可见范围
//    self.downScrollView.contentSize = CGSizeMake(HJDWidth - 20,400 );
    
    [self.viewM addSubview:self.downScrollView];

   
        CGFloat papreBtnX = HJDHorizontalMargin/2;
        CGFloat papreBtnY =  25+100;
        CGFloat papreBtnW = HJDWidth - HJDHorizontalMargin * 2 ;
        CGFloat papreBtnH = 40;
        self.papreBtn = [[UIButton alloc]initWithFrame:CGRectMake(papreBtnX, papreBtnY, papreBtnW, papreBtnH)];

        [self.papreBtn setBackgroundImage:[UIImage imageNamed:@"本周产检准备事项-----------------------前往)))"] forState:UIControlStateNormal];
        //    self.papreBtn.backgroundColor = [UIColor getColorWithHexNumber:@"FE93A2"];
        [self.papreBtn addTarget:self action:@selector(papreBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 150, 20)];
    lbl.backgroundColor = [UIColor whiteColor];
    lbl.text = @"产检时间安排";
    lbl.font = [UIFont systemFontOfSize:14];
    lbl.textColor = [UIColor getColorWithHexNumber:@"FD8599"];
    [self.papreBtn addSubview:lbl];
    [self.viewM addSubview:self.papreBtn];
    
        CGFloat viewMagrinX = 0;
        CGFloat viewMagrinY = CGRectGetMaxY(self.papreBtn.frame) +20 ;
    
        CGFloat viewMagrinW = HJDWidth;
        CGFloat viewMagrinH = 10;
        UIView *viewMarin = [[UIView alloc]initWithFrame:CGRectMake(viewMagrinX, viewMagrinY, viewMagrinW, viewMagrinH)];
    
        viewMarin.backgroundColor = [UIColor getColorWithHexNumber:@"F1F1EE"];
        [self.viewM addSubview:viewMarin];
    
    
        CGFloat btnMagrin = 29;
        CGFloat btnWith = (HJDWidth-  46 - btnMagrin *3)/4;
        CGFloat btnOneX = 13;
        CGFloat btnOneY = CGRectGetMaxY(viewMarin.frame) + 20;
        CGFloat btnOneW = btnWith;
        CGFloat btnOneH = btnWith;
        UIButton *btnOne = [[UIButton alloc]initWithFrame:CGRectMake(btnOneX, btnOneY, btnOneW, btnOneH)];
 
        [btnOne setBackgroundImage:[UIImage imageNamed:@"矢量智能对象@2x_1"] forState:UIControlStateNormal];
        [btnOne setRadius:btnOneW/2 borderWith:0 borderColor:nil];
    
        [btnOne addTarget:self action:@selector(oneClick) forControlEvents:UIControlEventTouchUpInside];
        [self.viewM addSubview:btnOne];
    
    
        UILabel *oneLbl = [[UILabel alloc]init];
        oneLbl.text = @"一键挂号";
        oneLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
        CGSize  oneLblSize = [oneLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:oneLbl.font,NSFontAttributeName ,nil]];
        CGFloat oneLblX = btnOneX + btnWith/2 - oneLblSize.width/2;
        CGFloat oneLblY = CGRectGetMaxY(btnOne.frame) + margin;
        oneLbl.frame = (CGRect){{oneLblX,oneLblY},oneLblSize};
    
        oneLbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
        [self.viewM addSubview:oneLbl];
    
    
        CGFloat btnTwoX = 13 + btnOneW +btnMagrin;
        CGFloat btnTwoY = btnOneY;
        CGFloat btnTwoW = btnWith;
        CGFloat btnTwoH = btnWith;
        UIButton *btnTwo = [[UIButton alloc]initWithFrame:CGRectMake(btnTwoX, btnTwoY, btnTwoW, btnTwoH)];
        [btnTwo setBackgroundColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnTwo addTarget:self action:@selector(twoClick) forControlEvents:UIControlEventTouchUpInside];
        [btnTwo setRadius:btnOneW/2 borderWith:0 borderColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnTwo setBackgroundImage:[UIImage imageNamed:@"矢量智能对象@2x_40"] forState:UIControlStateNormal];
        [self.viewM addSubview:btnTwo];
    
    
        UILabel *twoLbl = [[UILabel alloc]init];
        twoLbl.text = @"电子病历";
        twoLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
        CGSize  twoLblSize = [twoLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:twoLbl.font,NSFontAttributeName ,nil]];
        CGFloat twoLblX = btnTwoX + btnWith/2 - twoLblSize.width/2;
        CGFloat twoLblY = CGRectGetMaxY(btnTwo.frame) +margin ;
        twoLbl.frame = (CGRect){{twoLblX,twoLblY},twoLblSize};
        //    oneLbl.textAlignment = NSTextAlignmentCenter;
        twoLbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
        [self.viewM addSubview:twoLbl];
    
        CGFloat btnThreeX = 13 + (btnOneW +btnMagrin)*2;
        CGFloat btnThreeY = btnTwoY;
        CGFloat btnThreeW = btnWith;
        CGFloat btnThreeH = btnWith;
        UIButton *btnThree = [[UIButton alloc]initWithFrame:CGRectMake(btnThreeX, btnThreeY, btnThreeW, btnThreeH)];
        [btnThree setBackgroundColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnThree addTarget:self action:@selector(threeClick) forControlEvents:UIControlEventTouchUpInside];
        [btnThree setRadius:btnOneW/2 borderWith:0 borderColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnThree setBackgroundImage:[UIImage imageNamed:@"矢量智能对象@2x_96"] forState:UIControlStateNormal];
    
        [self.viewM addSubview:btnThree];
    
    
        UILabel *threeLbl = [[UILabel alloc]init];
        threeLbl.text = @"孕期管理";
        threeLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
        CGSize  threeLblSize = [threeLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:threeLbl.font,NSFontAttributeName ,nil]];
        CGFloat threeLblX = btnThreeX +btnWith/2 - threeLblSize.width/2;
        CGFloat threeLblY = CGRectGetMaxY(btnTwo.frame) +margin ;
        threeLbl.frame = (CGRect){{threeLblX,threeLblY},threeLblSize};
        //    oneLbl.textAlignment = NSTextAlignmentCenter;
        threeLbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
        [self.viewM addSubview:threeLbl];
    
        CGFloat btnFourX = 13 + (btnOneW +btnMagrin)*3;
        CGFloat btnFourY = btnThreeY;
        CGFloat btnFourW = btnWith;
        CGFloat btnFourH = btnWith;
        UIButton *btnFour = [[UIButton alloc]initWithFrame:CGRectMake(btnFourX, btnFourY, btnFourW, btnFourH)];
        [btnFour setBackgroundColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnFour addTarget:self action:@selector(fourClick) forControlEvents:UIControlEventTouchUpInside];
        [btnFour setRadius:btnOneW/2 borderWith:0 borderColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnFour setBackgroundImage:[UIImage imageNamed:@"-0"] forState:UIControlStateNormal];
    
        [self.viewM addSubview:btnFour];
    
    
        self.fourLbl = [[UILabel alloc]init];
        self.fourLbl.text = @"专属顾问";
        self.fourLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
        CGSize  fourLblSize = [ self.fourLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys: self.fourLbl.font,NSFontAttributeName ,nil]];
        CGFloat fourLblX = btnFourX + btnWith/2 -fourLblSize.width/2;
        CGFloat fourLblY = CGRectGetMaxY(btnFour.frame) +margin ;
        self.fourLbl.frame = (CGRect){{fourLblX,fourLblY},fourLblSize};
        //    oneLbl.textAlignment = NSTextAlignmentCenter;
        self.fourLbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
        [self.viewM addSubview: self.fourLbl];
    

    
}

//图片轮播
-(void)setupScrollView
{
    
    
    CGFloat scrollViewX = 10;
    CGFloat scrollViewY = IS_IPHONE_5?490:IS_IPHONE_6?510:IS_IPHONE_6_PLUS?520:490 ;
    CGFloat scrollViewW = HJDWidth-20;
    CGFloat scrollViewH = 250/2;
    
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(scrollViewX, scrollViewY,scrollViewW,scrollViewH)];
    self.scrollView.delegate = self;
//    self.scrollView.backgroundColor = [UIColor redColor];
    
    NSString *url = @"/app/getBanner.do";
    NSString *path = [Hurl stringByAppendingString:url];
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    [mgr POST:path parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *infoDic = (NSDictionary *)responseObject;
        self.array = [infoDic objectForKey:@"resultMap"];

        for (int i = 0; i<self.array.count; i++) {

            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i * (HJDWidth-20), 0,scrollViewW, scrollViewH)];
            NSString *info = infoDic[@"resultMap"][i][@"imageurl"];
            NSString *infoID = infoDic[@"resultMap"][i][@"id"];
            NSString *type = infoDic[@"resultMap"][i][@"type"];
            [self.typeArray addObject:type];
           
            [self.idArray addObject:infoID];
            
//             NSLog(@"selftypeArr==%@",self.typeArray);
            

            NSUserDefaults *da = [NSUserDefaults standardUserDefaults];
            [da setObject:infoID forKey:@"inID"];
        
            

            NSString *urlstring  = [NSString stringWithFormat:@"%@/%@",headImageUrl,info];
            UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlstring ]]];
            
            imageView.image = [image stretchableImageWithLeftCapWidth:image.size.width*0.5 topCapHeight:image.size.height*0.5];

//            imageView.contentMode = UIViewContentModeScaleAspectFit;
//           UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlstring ]]];
//            imageView.image = [UIImage imageWithStretchableName:image];
//                        imageView.clipsToBounds = YES;
//                    imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]];
            imageView.userInteractionEnabled = YES; // UIImageView默认不允许用户交互
            UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImage)];
            [imageView addGestureRecognizer:singleTap];
            [self.scrollView addSubview:imageView];
        }

        self.pageControl.numberOfPages = self.array.count;
         self.scrollView.contentSize = CGSizeMake(self.array.count * (HJDWidth-20), scrollViewH) ;
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       
//        NSLog(@"error%@",error);
    }];

    


    
    
    self.automaticallyAdjustsScrollViewInsets = NO; //ScrollView不能在viewController划到顶
    self.scrollView.pagingEnabled = YES;//分页设置
    self.scrollView.showsVerticalScrollIndicator = NO;//垂直移动
    self.scrollView.showsHorizontalScrollIndicator = NO;//水平移动
    self.scrollView.bounces = NO;//NO时滚动不会超出可见范围
    [self.scroll addSubview:self.scrollView];
    [self addTimer];
}

//阅读文章
-(void)setUpknowledge
{
    CGFloat articleX = 10;
    CGFloat articleY = IS_IPHONE_5?625:IS_IPHONE_6?645:IS_IPHONE_6_PLUS?655:625;
    CGFloat articleW = HJDWidth-HJDHorizontalMargin;
    CGFloat articleH = 60;
    UIView *articleView = [[UIView alloc]initWithFrame:CGRectMake(articleX, articleY, articleW, articleH)];
    articleView.backgroundColor = [UIColor whiteColor];
    
    
    [self.scroll addSubview:articleView];
    
    UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 30)];
    lbl.text = @"推荐阅读";
    lbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
    lbl.font = [UIFont systemFontOfSize:15];
    [articleView addSubview:lbl];
    
    UILabel *allLbl = [[UILabel alloc]initWithFrame:CGRectMake(HJDWidth-70, 10, 30, 30)];
    allLbl.text = @"全部";
    allLbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
    allLbl.font = [UIFont systemFontOfSize:15];
    [articleView addSubview:allLbl];
    
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(HJDWidth-35, 18, 8, 14)];
    img.image = [UIImage imageNamed:@"箭头"];
    [articleView addSubview:img];
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, HJDWidth, 30)];
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    [articleView addSubview:btn];
    
    UIView *hxView = [[UIView alloc]initWithFrame:CGRectMake(10, 50, HJDWidth- HJDHorizontalMargin*2, 1)];
    hxView.backgroundColor = [UIColor getColorWithHexNumber:@"D6D6D6"];
    [articleView addSubview:hxView];
    
    self.knowledgeTableView = [[UITableView alloc]initWithFrame:CGRectMake(10,articleY+60 , HJDWidth - HJDHorizontalMargin, 5000)];
    
    self.knowledgeTableView.delegate = self;
    self.knowledgeTableView.dataSource = self;
    [self.scroll addSubview:self.knowledgeTableView];
    
    
    NSString *url = @"/app/typeLst.do";
    NSString *path = [Hurl stringByAppendingString:url];
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [mgr POST:path parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic =(NSDictionary *)responseObject;
//        NSMutableArray *arr = dic[@"resultMap"];
         self.newIdArray = dic[@"resultMap"];
        
        for (int i = 0 ; i<self.newIdArray.count; i++) {
        
//                NSString *hits = dic[@"resultMap"][i][@"newsId"];
//            NSLog(@"hits==%@",hits);
//            
//            if (hits == nil) {
//                
//                [self.newIdArray removeObject:self.newIdArray[i]];
//                NSLog(@"ARR%@",self.newIdArray);
//            }

            
            
            NSString *str = dic[@"resultMap"][i][@"id"];
            [self.wenidArray addObject:str];
            NSUserDefaults *defa = [NSUserDefaults standardUserDefaults];
            [defa setObject:self.wenidArray  forKey:@"IDArr"];
            
            NSString *strTyep = dic[@"resultMap"][i][@"type"];
            [self.wentypeArray addObject:strTyep];
           
            [defa setObject:self.wentypeArray forKey:@"TypeArr"];
//            NSLog(@"responseObject==%@",responseObject);

        }
       
        self.statusArray = (NSMutableArray *)[HJDNewsModel mj_objectArrayWithKeyValuesArray:self.newIdArray];
        
        [self.knowledgeTableView reloadData];
//        NSLog(@"statusArray==%lu",(unsigned long)self.statusArray.count);
        self.scroll.contentSize = CGSizeMake(HJDWidth,articleY+134 + self.statusArray.count *115) ;
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"error = %@",error);
    }];
   

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.statusArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"cell";
    HJDNewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[HJDNewsTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    
    HJDNewsModel *news = self.statusArray[indexPath.row];
     NSString *urlStr =[NSString stringWithFormat:@"%@/%@",headImageUrl,news.imgUrl];
    cell.type.text = [NSString stringWithFormat:@"来自%@",news.type];
    
    
    if (news.imgUrl == nil) {
        cell.image.image = [UIImage imageNamed:@"孕"];
    }else{
    
    cell.image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]]];
    }
    cell.articleTitle.text = news.title;

    if ( [news.hits integerValue] >=1000) {
        CGFloat sum = [news.hits integerValue]/ 1000.0;
        cell.seeSum.text = [NSString stringWithFormat:@"%.1fk",sum];
    }else{
    cell.seeSum.text = [NSString stringWithFormat:@"%ld",(long)[news.hits integerValue]];

    }
    cell.seeText.text = @"阅读全文";
    
    CGSize articleSize = [ cell.articleTitle.text boundingRectWithSize:CGSizeMake(HJDWidth-130, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:cell.articleTitle.font,NSFontAttributeName, nil] context:nil].size;
    CGRect shiXianRect = cell.frame;
    shiXianRect.size.height = articleSize.height+94;
    cell.frame = shiXianRect;
     self.knowledgeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
   
    
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell  *CellH = [self tableView:tableView cellForRowAtIndexPath:indexPath];

    return CellH.frame.size.height;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    HJDWenZhangViewController *wen = [[HJDWenZhangViewController alloc]init];
    wen.newsModel = self.statusArray[indexPath.row];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:wen];
    [self presentViewController:nav animated:NO completion:nil];
    
//    NSLog(@"row==%@,,,,%lu",self.statusArray[indexPath.row],(unsigned long)self.statusArray.count);
}

-(void)btnClick
{
//    NSLog(@"全部");
    self.tabBarController.selectedIndex = 2;
    
}

-(void)addTimer
{
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(nextImage) userInfo:nil repeats:YES];
    self.timer = timer;
    //循环
    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
    [runLoop addTimer:timer forMode:NSRunLoopCommonModes];
    
}


-(void)nextImage
{
    NSInteger page = self.pageControl.currentPage;
    if (page == self.pageControl.numberOfPages-1) {
        page = 0;
    }else{
        page ++;
    }
    CGFloat offsetX = page * self.scrollView.frame.size.width;
    [UIView animateWithDuration:1.0 animations:^{
        self.scrollView.contentOffset = CGPointMake(offsetX, 0);
    }];
    
}

-(void)setupPageControl
{
    CGFloat pageY = CGRectGetMaxY(self.scrollView.frame)-20;
    self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake((self.view.frame.size.width-100)/2+20,pageY,40,20)];

    self.pageControl.enabled = NO;
    self.pageControl.currentPageIndicatorTintColor = [UIColor getColorWithHexNumber:@"5CC6AB"];
    self.pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
    [self.scroll insertSubview:self.pageControl aboveSubview:self.scrollView];
}



-(void)onClickImage
{
    
    if (self.pageControl.currentPage == 0) {
        
        NSString *str = self.typeArray[0];
        
        if ([str isEqualToString:@"yiyuan"]) {
            HJDYiYuanViewController *hosp = [[HJDYiYuanViewController alloc]init];
           
            [self presentViewController:hosp animated:YES completion:nil];
        }else if([str isEqualToString:@"huodong"]){
            HJDBannerTwoViewController *bannerTwo = [[HJDBannerTwoViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerTwo];
            NSString *str = self.idArray[0];
            NSUserDefaults *defaId = [NSUserDefaults standardUserDefaults];
            [defaId setObject:str forKey:@"BannerID1"];
            [self presentViewController:nav animated:YES completion:nil];
        }else if ([str isEqualToString:@"zhuanjia"]){
            HJDBannerOneViewController *bannerOne = [[HJDBannerOneViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerOne];
            [self presentViewController:nav animated:YES completion:nil];
            
        }
    
    }else if (self.pageControl.currentPage == 1){
        
        
        NSString *str = self.typeArray[1];
        
        if ([str isEqualToString:@"yiyuan"]) {
            HJDYiYuanViewController *hosp = [[HJDYiYuanViewController alloc]init];
           
            [self presentViewController:hosp animated:YES completion:nil];
        }else if([str isEqualToString:@"huodong"]){
            HJDBannerTwoViewController *bannerTwo = [[HJDBannerTwoViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerTwo];
            NSString *str = self.idArray[1];
            NSUserDefaults *defaId = [NSUserDefaults standardUserDefaults];
            [defaId setObject:str forKey:@"BannerID1"];
            
            [self presentViewController:nav animated:YES completion:nil];
        }else if ([str isEqualToString:@"zhuanjia"]){
            HJDBannerOneViewController *bannerOne = [[HJDBannerOneViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerOne];
            [self presentViewController:nav animated:YES completion:nil];
            
        }

        
    }else if (self.pageControl.currentPage == 2){
        
        
        
        NSString *str = self.typeArray[2];
        
        if ([str isEqualToString:@"yiyuan"]) {
            HJDYiYuanViewController *hosp = [[HJDYiYuanViewController alloc]init];
            
            [self presentViewController:hosp animated:YES completion:nil];
        }else if([str isEqualToString:@"huodong"]){
            HJDBannerTwoViewController *bannerTwo = [[HJDBannerTwoViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerTwo];
            NSString *str = self.idArray[2];
            NSUserDefaults *defaId = [NSUserDefaults standardUserDefaults];
            [defaId setObject:str forKey:@"BannerID1"];
            
            [self presentViewController:nav animated:YES completion:nil];
        }else if ([str isEqualToString:@"zhuanjia"]){
            HJDBannerOneViewController *bannerOne = [[HJDBannerOneViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerOne];
            [self presentViewController:nav animated:YES completion:nil];
            
        }

        
    
       
    }else if (self.pageControl.currentPage == 3){
        
        NSString *str = self.typeArray[3];
        
        if ([str isEqualToString:@"yiyuan"]) {
            HJDYiYuanViewController *hosp = [[HJDYiYuanViewController alloc]init];
            
            [self presentViewController:hosp animated:YES completion:nil];
        }else if([str isEqualToString:@"huodong"]){
            HJDBannerTwoViewController *bannerTwo = [[HJDBannerTwoViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerTwo];
            NSString *str = self.idArray[3];
            NSUserDefaults *defaId = [NSUserDefaults standardUserDefaults];
            [defaId setObject:str forKey:@"BannerID1"];
            
            [self presentViewController:nav animated:YES completion:nil];
        }else if ([str isEqualToString:@"zhuanjia"]){
            HJDBannerOneViewController *bannerOne = [[HJDBannerOneViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerOne];
            [self presentViewController:nav animated:YES completion:nil];
            
        }
    }else if (self.pageControl.currentPage == 4){
        NSString *str = self.typeArray[4];
        
        if ([str isEqualToString:@"yiyuan"]) {
            HJDYiYuanViewController *hosp = [[HJDYiYuanViewController alloc]init];
            
            [self presentViewController:hosp animated:YES completion:nil];
        }else if([str isEqualToString:@"huodong"]){
            HJDBannerTwoViewController *bannerTwo = [[HJDBannerTwoViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerTwo];
            NSString *str = self.idArray[4];
            NSUserDefaults *defaId = [NSUserDefaults standardUserDefaults];
            [defaId setObject:str forKey:@"BannerID1"];
            
            [self presentViewController:nav animated:YES completion:nil];
        }else if ([str isEqualToString:@"zhuanjia"]){
            HJDBannerOneViewController *bannerOne = [[HJDBannerOneViewController alloc]init];
            HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerOne];
            [self presentViewController:nav animated:YES completion:nil];
            
        }
 
        
    }
        
}


-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    
    //将要拖拽是停止定时器
    [self.timer invalidate];
}
//结束拖拽调用
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    [self addTimer];
}

//时间准备表
-(void)papreBtnClick
{
//     HJDCTimeViewController *cTime = [[HJDCTimeViewController alloc]init];
    
    HJDPapreViewController *detail = [[HJDPapreViewController alloc]init];
    HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:detail];
    [self presentViewController:nav animated:YES completion:nil];

}

-(void)fourClick
{
    
//     检测是否安装了QQ
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
        
        NSUserDefaults *qqkf = [NSUserDefaults standardUserDefaults];
        NSString *qqKF = [qqkf objectForKey:@"qqKF"];
        if (qqKF != nil) {
            UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectZero];
            NSString *string = [NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",qqKF];
            [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:string]]];
            [self.view addSubview:webView];
//                    NSLog(@"你安装了qq");
            
        }else{
       
        
        
        NSString * url = @"/app/kefu.do";
        NSString *path = [Hurl stringByAppendingString:url];
        AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        [mgr POST:path parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//            NSLog(@"success%@",responseObject);
            NSDictionary *info = (NSDictionary *)responseObject;
            NSString *success = info[@"resultCode"];
            NSString *strqq = info[@"resultMap"];
            
            NSUserDefaults *defa = [NSUserDefaults standardUserDefaults];
            [defa setObject:strqq forKey:@"qqKF"];
            if ([success integerValue]==0) {
                UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectZero];
                NSString *string = [NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",strqq];
                [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:string]]];
                [self.view addSubview:webView];
            }
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//            NSLog(@"error%@",error);
        }];
    }
    
//        NSLog(@"你安装了qq");
        
    }else{
        [MBProgressHUD  showError:@"你还没有安装QQ,请安装QQ"];
//        NSLog(@"没有安装");
    }
    
    }

-(void)oneClick
{
    HJDRegistrationViewController *registration = [[HJDRegistrationViewController alloc]init];
    HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:registration];
    [self presentViewController:nav animated:YES completion:nil];
}

-(void)twoClick
{
    statusCase = [[[NSUserDefaults standardUserDefaults]stringForKey:@"stusCase"] intValue];
 
    if (statusCase ==0) {
        HJDGestationViewController *gestation = [[HJDGestationViewController alloc]init];
        HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:gestation];
        [self presentViewController:nav animated:YES completion:nil];
    }else if (statusCase ==1){
        HJDFileViewController *file = [[HJDFileViewController alloc]init];
        HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:file];
        [self presentViewController:nav animated:YES completion:nil];
    }
}

-(void)threeClick
{
    HJDPofileControllerr *pofile = [[HJDPofileControllerr alloc]init];
    HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:pofile];
    [self presentViewController:nav animated:YES completion:nil];//    [self.navigationController pushViewController:pofile animated:YES];
}

//-(void)resultClick
//{
//    NSLog(@"咨询");
//}


-(void)upDayBtnClick{
    
    
    if (INDex-1<0) {
        [MBProgressHUD showError:@"么么哒，今天是本周任务安排第一天噢！"];
        
    }else{
        INDex -=1;
        [self chuanzhi:INDex];
    }

    
    
    
    
}

-(void)nextDayBtnClick{
    if (INDex+1> 6) {
        [MBProgressHUD showError:@"亲,本周任务安排已经结束，敬请期待下周安排"];

    }else{
        INDex+=1;
        [self chuanzhi:INDex];
    }
    

   
}




//添加内容
-(void)setUpContent
{
    HJDMondayTableViewController *social = [[HJDMondayTableViewController alloc]init];
    social.title = @"一";
    [self addChildViewController:social];
    HJDTuesdayTableViewController *social1 = [[HJDTuesdayTableViewController alloc] init];
    social1.title = @"二";
    [self addChildViewController:social1];
    
    HJDWednesdayTableViewController *social2 = [[HJDWednesdayTableViewController alloc] init];
    social2.title = @"三";
    [self addChildViewController:social2];
    
    HJDThursdayTableViewController *social3 = [[HJDThursdayTableViewController alloc] init];
    social3.title = @"四";
    [self addChildViewController:social3];
    
    HJDFridayTableViewController *social4 = [[HJDFridayTableViewController alloc] init];
    social4.title = @"五";
    [self addChildViewController:social4];
    
    HJDSaturdayTableViewController *social5 = [[HJDSaturdayTableViewController alloc] init];
    social5.title = @"六";
    [self addChildViewController:social5];
    
    HJDSundayTableViewController *social6 = [[HJDSundayTableViewController alloc] init];
    social6.title = @"日";
    [self addChildViewController:social6];
    
}


/**
 *   添加标题
 */
-(void)setUpTitle
{
    CGFloat lblW = (HJDWidth -45 -30)/7;
    CGFloat lblY = 0;
    CGFloat lblH = self.upScrollView.frame.size.height;
    for ( int i =0; i< 7; i++) {
        HJDLabel *label = [[HJDLabel alloc] init];
        label.text = [self.childViewControllers[i] title];
        CGFloat labelX = i * lblW;
        label.frame = CGRectMake(labelX, lblY, lblW, lblH);
        
        //        点击手势监听
        [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelClick:)]];
        //        得到索引
        label.tag = i;
        
        [self.upScrollView addSubview:label];
        
        
        NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
        NSDateComponents *comp = [[NSDateComponents alloc]init];
        NSInteger flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
        NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
        NSDate *nowDate = [NSDate date];
        
        comp = [calendar components:flags fromDate:nowDate];
        long int week = [comp weekday];
        if (week == 1) {
            week = 8;
        }
        NSInteger shi = week -2;
        

        //        显示label
        if (i == shi) { // 最前面的label
            label.scale = 1.0;
        }
        
    }
    
    // 设置contentSize
    self.upScrollView.contentSize = CGSizeMake(7 * lblW, 0);
    self.downScrollView.contentSize = CGSizeMake((7 * [UIScreen mainScreen].bounds.size.width), 0);
}


//监听顶部label点击
-(void)labelClick:(UITapGestureRecognizer *)tap
{
    
    //    取出被点击label的索引
    INDex = tap.view.tag;
    [self chuanzhi:INDex];
    //    让底部的内容scrollView滚动到对应的位置
}
-(void)chuanzhi:(NSInteger)shu
{
    
     NSInteger h = n - one + shu;
    
    NSInteger c = 280 - n + one - shu;
    if (c <= 0 ) {
        c = 0;
    }
    self.timeLbl.text = [NSString stringWithFormat:@"%ld",(long)h];
    self.babyDayLbl.text = [NSString stringWithFormat:@"%ld",(long)c];

    CGPoint offset1 = self.downScrollView.contentOffset;
    offset1.x = shu * self.downScrollView.frame.size.width;
    [self.downScrollView setContentOffset:offset1 animated:YES];
    

    
    NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
    NSTimeInterval  oneDay = 24*60*60;
    
    [inputFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSDate *inputDate = [inputFormatter dateFromString:self.attenModel.time];
    
    
    NSDate *nextDate = [NSDate dateWithTimeInterval:-oneDay*one +oneDay * shu sinceDate:inputDate];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *comp = [[NSDateComponents alloc]init];
    NSInteger flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    
    comp = [calendar components:flags fromDate:nextDate];
    NSInteger month = [comp month];
    NSInteger day = [comp day];
    
    self.dayLbl.text = [NSString stringWithFormat:@"%ld.",(long)day];
    self.dayLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:25];
    CGSize  dayLblSize = [self.dayLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.dayLbl.font,NSFontAttributeName ,nil]];
    CGFloat dayLblX = HJDWidth - 80;
    CGFloat dayLblY = 160;
    self.dayLbl.frame = (CGRect){{dayLblX,dayLblY},dayLblSize};
    
    self.dateLbl.text = [NSString stringWithFormat:@"%ld",(long)month];
    self.dateLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:15];
    CGSize  dateLblSize = [self.dateLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.dateLbl.font,NSFontAttributeName ,nil]];
    CGFloat dateLblX = CGRectGetMaxX(self.dayLbl.frame);
    CGFloat dateLblY = dayLblY + 9;
    self.dateLbl.frame = (CGRect){{dateLblX,dateLblY},dateLblSize};
    
}

/**
 * scrollView结束了滚动动画以后就会调用这个方法（比如- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;方法执行的动画完毕后）
 */

-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
    
    CGFloat width = self.downScrollView.frame.size.width;
    CGFloat height = self.downScrollView.frame.size.height;
    CGFloat offsetX = self.downScrollView.contentOffset.x;

    //   当前位置需要显示的控制器的索引
   INDex = offsetX / width;
    
     [self chuanzhi:INDex];
//    遍历label，不同于labe都显示之前的状态
        HJDLabel *labe = self.upScrollView.subviews[INDex];
        for (HJDLabel *otherLbl in self.upScrollView.subviews) {
            if (otherLbl != labe)
                otherLbl.scale =0.0;
                }
    
    //   取出需要显示的控制器
    UIViewController *willShowVC = self.childViewControllers[INDex];
    
    //    如果当前位置显示，就直接返回
    if ([willShowVC isViewLoaded]) return;
    // 添加控制器的view到contentScrollView中
    willShowVC.view.frame = CGRectMake(offsetX, 0, width, height);
    [self.downScrollView addSubview:willShowVC.view];
//
    
}

/**
 * 手指松开scrollView后，scrollView停止减速完毕就会调用这个
 */
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

    [self scrollViewDidEndScrollingAnimation:scrollView];
   
}
/**
 *   只要scrollView在滚动，就会调用
 */


-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if ([scrollView isEqual:self.downScrollView]) {
    
        CGFloat scale = scrollView.contentOffset.x / scrollView.frame.size.width;
        if (scale < 0 || scale > self.upScrollView.subviews.count -1) return;
        
//        // 获得需要操作的左边label
        NSInteger leftIndex = scale;
        
        HJDLabel *leftLabel = self.upScrollView.subviews[leftIndex];
        
//
//        // 获得需要操作的右边label
        NSInteger rightIndex = leftIndex + 1;
        HJDLabel *rightLabel = (rightIndex == self.upScrollView.subviews.count) ? nil : self.upScrollView.subviews[rightIndex];
//
//        // 右边比例
        CGFloat rightScale = scale - leftIndex;
//        // 左边比例
        CGFloat leftScale = 1 - rightScale;
        
//        // 设置label的比例
        leftLabel.scale = leftScale;
        rightLabel.scale = rightScale;

    }
    else if ([scrollView isEqual:self.scrollView]) {
        CGPoint page = self.scrollView.contentOffset;
        self.pageControl.currentPage = page.x /[UIScreen mainScreen].bounds.size.width + 0.5;
    }
    
   }




@end
